package com.twinkle.controller.cluster;

import com.twinkle.model.ClusterResult;
import com.twinkle.service.ClusterResultService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @title: ClassifierResultController
 * @description: 聚类算法结果接口类
 * @author: Paul
 * @date: 2023/3/23 13:34
 */
@Controller
@RequestMapping("/algo/clusterresult")
public class ClusterResultController {

    @Autowired
    ClusterResultService clusterResultService;

    @RequestMapping(value = "/resultpage", method = { RequestMethod.GET })
    public String resultPage(HttpServletRequest request) {
        return "algo_plat/cluster/resultgrid";
    }

    @ResponseBody
    @RequestMapping(value="/resultlist" , method={RequestMethod.POST})
    public String resultList(HttpServletRequest request){
        String page = request.getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数
        String rows = request.getParameter("rows"); // 取得每页显示行数，,注意这是jqgrid自身的参数
        return clusterResultService.getAllClusterResultJson(Integer.parseInt(page) , Integer.parseInt(rows));
    }

    @RequestMapping(value="/resultdetail" , method={RequestMethod.GET})
    public String getResultDetail(Model model, @Param("id") String id){
        ClusterResult clusterResult = clusterResultService.getClusterResultById(id);
        model.addAttribute("algoResult", clusterResult);
        return "algo_plat/algo_cluster/kmeans_result";
    }

    @ResponseBody
    @RequestMapping(value="/search" , method={RequestMethod.POST})
    public String search(HttpServletRequest request, @Param("algoName") String algoName, @Param("appName") String appName){
        String page = request.getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数
        String rows = request.getParameter("rows"); // 取得每页显示行数，,注意这是jqgrid自身的参数
        System.out.println("page : " + page + ";rows : " + rows);
        return clusterResultService.getAllClusterResultJsonBySearch(Integer.parseInt(page) , Integer.parseInt(rows), algoName, appName);
    }

}
